<template>
    <div class="lefter-btn-container">
        <div :class="[checked?'lefter-btn-box-active':'lefter-btn-box']" @click="checkBtn">
            <div class="message-box">
                <img :src="getIcon(checked)">
                <div style="width: 10px"></div>
                {{name}}
            </div>
        </div>
    </div>
</template>

<script>

export default {
    name: "lefterBtn",
    props:['id', 'checked', 'name', 'type'],
    emit:['checkLefterBtn'],
    setup(props, context) {

        function getIcon(checked) {
            if (checked === true) {
                return new URL(`../../../assets/main/lefter/${props.id + 'Checked'}.png`, import.meta.url).href
            } else {
                return new URL(`../../../assets/main/lefter/${props.id}.png`, import.meta.url).href
            }
        }

        function checkBtn() {
            context.emit('checkLefterBtn', props.id, props.type)
        }

        return {
            checkBtn,
            getIcon
        }
    }
}
</script>

<style scoped>
.lefter-btn-container {
    position: relative;
    padding: 10px 10px 0 10px;
    width: calc(100% - 20px);
    height: 50px;
}

.lefter-btn-box {
    position: relative;
    width: 100%;
    height: 100%;
    background-color: rgb(243, 243, 245);
    border-radius: 5px;
    color: red;
    transition: all 300ms ease-in-out;
}

.lefter-btn-box:hover {
    background-color: white;
    box-shadow: 0 2px 10px rgb(235, 235, 236);
}

.lefter-btn-box-active {
    position: relative;
    width: 100%;
    height: 100%;
    background-color: red;
    border-radius: 5px;
    color: white;
    transition: all 300ms ease-in-out;
}

.message-box {
    pointer-events: none;
    display: flex;
    align-items: center;
    position: absolute;
    padding: 10px;
    width: calc(100% - 20px);
    height: calc(100% - 20px);
    font-size: 20px;
}

.message-box img {
    width: 30px;
    height: 30px;
}
</style>